/******************************************
  	 月经初始化
   *******************************************/
var mensesDurationArray = new Array();
var mensesPeriodArray = new Array();
var mensesStartDateArray = new Array();
var mensesChartLabelArray = new Array();
var INTENT_SHOW_PERIOD_NUM = 6;

function initMensesChartData(){
    initMensesChartZone();
    initMensesDurationArray();
    initMensesPeriodArray();
    initMensesChartLabelArray();
}


function initMensesChartZone(){
    var mensesChartHeight = window.innerHeight * mensesChartHeightPercentage;
    var mensesChartWidth = window.innerWidth;
    
    setMensesChartSreen(mensesChartWidth, mensesChartHeight);
}

function setMensesChartSreen(mensesChartWidth, mensesChartHeight){
    document.getElementById('mensesChart').style.width = mensesChartWidth + "px";
    document.getElementById('mensesChart').style.height = mensesChartHeight + "px";
}

//经期
function initMensesDurationArray(){
    var atualShowPeriodNum = getActualShowPeriod();

    //只需获取 Len - 1 个经期即可，因为周期个数为 Len - 1 个。画最近atualShowPeriodNum条数据。
    var j = 0;

    for (var i = atualShowPeriodNum - 1; i >= 0; i--) {
        var tempStartDate = customerDataMensesStartDateArray[mensesShowLen - j - 1];
        var tempEndDate = customerDataMensesEndDateArray[mensesShowLen - j - 1];
        mensesDurationArray.unshift(getDaysDuration(tempStartDate, tempEndDate));
        mensesStartDateArray.unshift(customerDataMensesStartDateArray[mensesShowLen - j - 1]);
        j++;        
    }
}

//周期
function initMensesPeriodArray(){
    var atualShowPeriodNum = getActualShowPeriod();

    //只需获取 Len - 1 个经期即可，因为周期个数为 Len - 1 个。画最近atualShowPeriodNum条数据。
    var j = 0;
    for (var i = atualShowPeriodNum - 1; i >= 0; i--) {
        var oldStartDate = customerDataMensesStartDateArray[mensesShowLen - j - 1];
        var newStartDate = customerDataMensesStartDateArray[mensesShowLen - j];
        mensesPeriodArray.unshift(getDaysDuration(oldStartDate, newStartDate) - 1);
        j++;
    }
}

function getActualShowPeriod(){
    var atualShowPeriodNum = getMin(INTENT_SHOW_PERIOD_NUM, mensesShowLen);
    
    return atualShowPeriodNum;
}

function getMin(m, n){
    if (m <= n) return m;
    else return n;
}

function initMensesChartLabelArray(){
	var atualShowPeriodNum = getActualShowPeriod();    
    for (var i = 0; i < atualShowPeriodNum; i++) {
    	mensesChartLabelArray[i] =(getBriefDate(mensesStartDateArray[i]) +"   "+mensesDurationArray[i] + "/" + mensesPeriodArray[i]);
    }
    
    if(atualShowPeriodNum < INTENT_SHOW_PERIOD_NUM)
    	for(var j = atualShowPeriodNum; j < INTENT_SHOW_PERIOD_NUM; j++)
    		mensesChartLabelArray[j] = '';
}
